from django.shortcuts import render,redirect
from booktest.models import BookInfo
from datetime import date
from django.http import HttpResponse,HttpResponseRedirect


def index(request):
    books = BookInfo.objects.all()
    return render(request,'booktest/index.html',{'books':books})


def create(request):
    b = BookInfo()
    b.btitle='流星蝴蝶剑'
    b.bpub_date=date(1990,1,1)
    b.save()
    # return HttpResponse('ok')
    # return  HttpResponseRedirect('/index')
    return redirect('/index')

def delete(request,bid):
    '''删除惦记的图书'''
    book = BookInfo.objects.get(id=bid)
    book.delete()
    # return HttpResponseRedirect('/index')
    return  redirect('/index')
